// pages/index/index.js
import {formatDate,request} from "../../utils/utils";
import api from "../../utils/api";
import QQMapWX from "../../utils/qqmap-wx-jssdk.min";
var _key = '3QRBZ-XQL6I-L4KGW-5ETKY-MPOL2-HXB6G';
var qqmapsdk = new QQMapWX({
  key: _key
});

Page({
  data: {
		images:[],
    nowData:'',
    list:[],
		ads:''
  },
  onLoad (options) {},
  onReady () {
    this.getDataPic();
    this.setNow();
    this.getList();
		this.getLocation();
  },
	getDataPic(){
    this.data.images = [
      'https://www.doapis.com/doapis/public/resources/1625043676791.jpg',
      'https://www.doapis.com/doapis/public/resources/1625042624564.jpg'			
    ]
    this.setData({
      images:this.data.images
    })
	},
	getLocation(){
		var that = this;
		wx.getLocation({
		 type: 'gcj02', //返回可以用于wx.openLocation的经纬度
		 success (res) {
			 const latitude = res.latitude
			 const longitude = res.longitude
			 console.log(res);
			 qqmapsdk.reverseGeocoder({
				location: {
					latitude:  latitude,
					longitude: longitude
				},
				get_poi: 0,
				success(res1){
					console.log(res1.result.address);
					that.setData({ads:res1.result.address})	
				}					 
			 })
		 },
		fail:function(res){
			console.log("获取经纬度失败"+JSON.stringify(res))
		}		 
		})		
					
	},
  setNow(){
    let _arr = formatDate('','1');
    this.data.nowData = `${_arr[1]}月${_arr[2]}日 ${_arr[3]}`;
    this.setData({ nowData:this.data.nowData });   
  },
  async getList(){
    let list = await request({url:api.getContentList, data:{page:1,pageSize:3}});
    this.setData({ list:list.data.data }); 
  }	
})